home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / setup_keys.pro < prev    next >
Text File  |  1997-07-08  |  6KB  |  165 lines

  1. ; $Id: setup_keys.pro,v 1.4 1997/03/05 19:20:58 ali Exp $
  2. ;
  3. ; Copyright (c) 1989-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ;+
  7. ; NAME:
  8. ;    SETUP_KEYS
  9. ;
  10. ; PURPOSE:
  11. ;    Set up function keys for use with IDL.
  12. ;
  13. ;    Under Unix, the number of function keys, their names, and the
  14. ;    escape sequences they send to the host computer vary
  15. ;    enough between various keyboards that IDL cannot be
  16. ;    written to understand all keyboards.  Therefore, it provides
  17. ;    a very general routine named DEFINE_KEY that allows the
  18. ;    user to specify the names and escape sequences of function keys.
  19. ;
  20. ;    SETUP_KEYS uses user input (via keywords), the TERM environment
  21. ;    variable and the type of machine the current IDL is running on
  22. ;    to determine what kind of keyboard you are using, and then uses
  23. ;    DEFINE_KEY to enter the proper definitions for the function keys.
  24. ;
  25. ;    The need for SETUP_KEYS has diminished in recent years because
  26. ;    most Unix terminal emulators have adopted the ANSI standard for
  27. ;    function keys, as represented by VT100 terminals and their many
  28. ;    derivatives, as well as xterm and the newer CDE based dtterm.
  29. ;    The current version of IDL already knows the function keys of such
  30. ;    terminals, so SETUP_KEYS is not required. However, SETUP_KEYS is
  31. ;    still needed to define keys on non-ANSI terminals such as the
  32. ;    Sun shelltool, SGI iris-ansi terminal emulator, or IBM's aixterm.
  33. ;
  34. ; CATEGORY:
  35. ;    Misc.
  36. ;
  37. ; CALLING SEQUENCE:
  38. ;    SETUP_KEYS
  39. ;
  40. ; INPUTS:
  41. ;    None.
  42. ;
  43. ; KEYWORD PARAMETERS:
  44. ;    NOTE:  If no keyword is specified, SETUP_KEYS uses the TERM
  45. ;    environment variable and !VERSION to make an educated guess of
  46. ;    the keyboard being used. This guess is not foolproof, but is
  47. ;    usually correct).
  48. ;
  49. ;    ANSI:
  50. ;    VT200:    Establish function key definitions for a DEC VT200. The
  51. ;        VT200 is a superset of the ANSI standard and can be used
  52. ;        for ANSI based terminal emulators such as xterm.
  53. ;
  54. ;
  55. ;     EIGHTBIT:    When establishing VT200 function key definitions,
  56. ;        use the 8-bit versions of the escape codes instead
  57. ;        of the default 7-bit.
  58. ;    HP9000:    Establish function key definitions for an HP 9000 series
  59. ;        300 keyboard.  Although the HP 9000 series 300 supports both
  60. ;        xterm and hpterm windows, IDL supports only user-definable
  61. ;        key definitions in xterm windows - hpterm windows use
  62. ;        non-standard escape sequences which IDL does not attempt
  63. ;        to handle.
  64. ;
  65. ;    IBM    Establish function key definitions for an IBM keyboard.
  66. ;
  67. ;    MIPS:    Establish function key definitions for a Mips RS series
  68. ;        keyboard.
  69. ;
  70. ;    SGI:    Establish function key definitions for SGI keyboards.
  71. ;
  72. ;    SUN:    Establish function key definitions for a Sun shelltool
  73. ;        terminal emulator, as well as some definitions for the
  74. ;        obsolete Sun3 keyboard.
  75. ;
  76. ;
  77. ;  APP_KEYPAD:    Will define escape sequences for the group of keys
  78. ;        in the numeric keypad, enabling these keys to be programmed
  79. ;        within IDL.
  80. ;
  81. ;  NUM_KEYPAD:    Will disable programmability of the numeric keypad.
  82. ;
  83. ; OUTPUTS:
  84. ;    None.
  85. ;
  86. ; COMMON BLOCKS:
  87. ;    None.
  88. ;
  89. ; SIDE EFFECTS:
  90. ;    The definitions for the function keys are entered.  The new keys
  91. ;    can be viewed using the command HELP, /KEYS.
  92. ;
  93. ; MODIFICATION HISTORY:
  94. ;    AB, 26 April 1989
  95. ;    TJA, July 1990.    Added key definitions for HP 9000 series 300, as
  96. ;            well as Mips RS series; also rearranged code into 
  97. ;            separate files.
  98. ;
  99. ;    SMR, April, 1991.  Added key definitions for SGI and PSTERM
  100. ;    AB, 22 November 1994, Added key definitions for IBM.
  101. ;    AB, 5 March 1997, Update for the current state of keyboards, which
  102. ;        increasingly emulate ANSI behavior. This simplifies things.
  103. ;        Added the ANSI keyword. Removed the PSTERM keyword because
  104. ;        Sun's psterm program no longer exists. Added code that uses
  105. ;        the TERM environment variable to better diagnose the keyboard.
  106. ;        General cleanup.
  107. ;-
  108.  
  109. PRO setup_keys, ANSI=ANSI, HP9000 = HP9000, IBM = IBM, MIPS = MIPS, $
  110.     SGI = SGI, SUN = SUN, VT200 = VT200, _EXTRA=EXTRA
  111.  
  112. ON_ERROR,2                              ;Return to caller if an error occurs
  113.  
  114. ; The GUI based front ends don't use this mechanism. Quietly return instead
  115. ; of throwing an error so that people who use both can call this from
  116. ; their startup files.
  117. if ((FSTAT(0)).isagui ne 0) then return
  118.  
  119. ; VMS has a tty based interface available, but the keys are fixed.
  120. IF (!VERSION.OS EQ 'vms') THEN $
  121.   MESSAGE, 'VMS key names are "pre-set" by the Screen Management Utility.'
  122.  
  123.  
  124. ; Decide what kind of keyboard were defining. The rules used to pick this
  125. ; are:
  126. ;    1) If the user indicates the keyboard using a keyword, use that.
  127. ;    2) If the TERM environment variable is a type we understand, use
  128. ;       that. This allows us to work with terminal emulators displaying
  129. ;       across a network.
  130. ;    3) If !VERSION.OS indicates a keyboard that is a unique special case
  131. ;       that we understand, use that. This is better than a blind guess.
  132. ;    4) If all else fails, assume it is an ANSI keyboard.
  133. term = GETENV('TERM')
  134. os = !version.os
  135. case  1 of
  136.   KEYWORD_SET(ANSI)    : cmd = 'SKEY_DEC'
  137.   KEYWORD_SET(HP9000)    : cmd = 'SKEY_HP'
  138.   KEYWORD_SET(IBM)    : cmd = 'SKEY_IBM'
  139.   KEYWORD_SET(MIPS)    : cmd = 'SKEY_MIPS'
  140.   KEYWORD_SET(SUN)     : cmd = 'SKEY_SUN'
  141.   KEYWORD_SET(VT200)    : cmd = 'SKEY_DEC'
  142.   KEYWORD_SET(SGI)    : cmd = 'SKEY_SGI'
  143.  
  144.   (term eq 'xterm') or (term eq 'dtterm') : cmd = 'SKEY_DEC'
  145.   (term eq 'iris-ansi') : cmd = 'SKEY_SGI'
  146.   (term eq 'aixterm')    : cmd = 'SKEY_IBM'
  147.   (term eq 'hpterm')    : cmd = 'SKEY_HP'
  148.  
  149.   (os eq 'sunos')    : cmd = 'SKEY_SUN'
  150.   (os eq 'hp-ux')    : cmd = 'SKEY_HP'
  151.   (os eq 'IRIX')    : cmd = 'SKEY_SGI'
  152.   (os eq 'AIX')        : cmd = 'SKEY_IBM'
  153.  
  154.   else            : cmd = 'SKEY_DEC'
  155. ENDCASE
  156.  
  157. ; Call the appropriate sub-module to do the work
  158. if (n_elements(extra) eq 0) THEN BEGIN
  159.   CALL_PROCEDURE, cmd
  160. endif else begin
  161.   CALL_PROCEDURE, cmd, _extra=extra
  162. ENDELSE
  163.  
  164. END
  165.